package com.it.web.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.Map;

 /** @Author ShuYY
 * @Description 用于捕获全局异常
 * @Date 2020/10/25
 **/

@ControllerAdvice//切面
public class GlobalExceptionHandler {

    @ExceptionHandler(RuntimeException.class)//捕获运行时异常
    @ResponseBody//返回json
    public Map<String,Object> exceptionHandler(){//异常处理方法，自定义
        Map<String, Object> map = new HashMap<String, Object>();
        map.put("errorCode", "101");
        map.put("errorMsg", "系统错误!");
        return map;
    }

}
